package com.mvd.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mvd.app.R;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.model.TianjinReportModel;

import java.util.Arrays;
import java.util.List;

/**
 * Created by leilei on 2023/2/15.
 */

public class TianjinReportAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private Context context;
    private List<TianjinReportModel> data;
    private List<byte[]> zpByteList;

    public TianjinReportAdapter(Context context, List<TianjinReportModel> data, List<byte[]> zpByteList) {
        this.context = context;
        this.data = data;
        this.zpByteList = zpByteList;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return zpByteList.size();
    }

    @Override
    public Object getItem(int position) {
        return zpByteList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_tianjin_report,
                    null);
            holder.zpbh = (TextView) convertView
                    .findViewById(R.id.item_tianjin_report_zpbh);
            holder.reportIv = (ImageView) convertView
                    .findViewById(R.id.item_tianjin_report_iv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String zpbh = data.get(0).getPhotodes().get(position).getZpbh();
        holder.zpbh.setText(zpbh);
//        holder.reportIv.setImageDrawable();
//        String base64Str = zpList.get(position);
////        base64Str = base64Str.replace("data:image/jpeg;base64,", ""); //实际返回的结果不存在base64前缀
//        byte[] decodedString = Base64.decode(base64Str, Base64.DEFAULT);
        byte[] decodedString = zpByteList.get(position);
        String logStr = "TianjinReportAdapter---position==" + position + "---decodedString===" + Arrays.toString(decodedString);
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        Glide.with(context).load(decodedString).into(holder.reportIv);
        return convertView;
    }

    class ViewHolder {
        TextView zpbh;
        ImageView reportIv;
    }
}
